<?php

namespace Biz\model\activity;

class CplRecord extends \Doraemon\pockets\datebase\BaseDbModel
{
    const _CONFIG_FILE_ = 'db_shop';

    const _CONFIG_SELECT_ = 'db_activity';

    const _DATABASE_ = 'shop_activity';

    const _TABLE_NAME = 'cpl_record';



    public static function inserRecord($data)
    {
        $data['addtime'] = date("Y-m-d H:i:s");
        if (self::insert($data)->rowcount()) {
            return self::id();
        } else {
            return false;
        }
    }

    public static function updateRecord($data)
    {
        $data['addtime'] = date("Y-m-d H:i:s");
        return self::update($data,['id' => $data['id']]);
    }


    public static function getRecordCountByModuleId($module_id)
    {
         $sql = 'SELECT count(distinct phone,user_name) as count from '.self::_TABLE_NAME." where module_id=".$module_id;
         $count = self::query($sql)->fetchAll();
         return $count[0]['count'] ? : 0;
    }


    public static function getRecordByCondition($condition)
    {
        return self::get("*" , $condition);
    }


    public static function getCplByModuleId($module_ids , $active_uid)
    {

       return self::get("*"  , [
            'AND'=>[
                'module_id' => $module_ids ,
                'active_uid' => $active_uid
            ],
            'ORDER' => ['addtime' => 'DESC'],
			'LIMIT' => 1
        ]);
    }
}